package com.wang.system.controller;

import com.wang.common.core.controller.BaseController;


import com.wang.common.core.domain.R;
import com.wang.common.core.domain.TableDataInfo;
import com.wang.system.domain.exam.dto.ExamAddDTO;
import com.wang.system.domain.exam.dto.ExamEditDTO;
import com.wang.system.domain.exam.dto.ExamQueryDTO;
import com.wang.system.domain.exam.dto.ExamQuestionDTO;
import com.wang.system.domain.exam.vo.ExamDetailVO;
import com.wang.system.domain.exam.vo.ExamVO;
import com.wang.system.service.IExamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Tag(name = "竞赛管理接口")
@RequestMapping("/exam")
@RestController
public class ExamController {

    @Autowired
    private IExamService examService;

    @Operation(summary = "获取竞赛列表")
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO ExamQueryDTO){
        List<ExamVO> list = examService.list(ExamQueryDTO); //查询出来的是当前页码下的信息
        return BaseController.getTableDataInfo(list);
    }

    @Operation(summary = "添加竞赛")
    @PostMapping("/add")
    public R<String> add(@RequestBody @Validated ExamAddDTO ExamAddDTO){
        return R.success(examService.add(ExamAddDTO));
    }


    @GetMapping("/detail")
    @Operation(summary = "查询指定竞赛详细信息")
    public R<ExamDetailVO> detail(Long examId){
        return R.success(examService.detail(examId));
    }

    @PutMapping("/edit")
    @Operation(summary = "编辑竞赛信息")
    public R<Void> edit(@RequestBody @Validated ExamEditDTO ExamEditDTO){
        return BaseController.toR(examService.edit(ExamEditDTO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除指定竞赛")
    public R<Void> delete(Long examId){
        return BaseController.toR(examService.delete(examId));
    }

    @Operation(summary = "为指定竞赛添加题目")
    @PostMapping("/question/add")
    public R<Void> questionAdd(@Validated @RequestBody ExamQuestionDTO examQuestionDTO){
        return BaseController.toR(examService.questionAdd(examQuestionDTO));
    }

    @Operation(summary = "为指定竞赛删除题目")
    @DeleteMapping("/question/delete")
    public R<Void> questionDelete(Long examId,Long questionId){
        return BaseController.toR(examService.questionDelete(examId,questionId));
    }

    @PutMapping("/publish")
    @Operation(summary = "发布竞赛")
    public R<Void> publish(Long examId){
        return BaseController.toR(examService.publish(examId));
    }

    @PutMapping("/cancelPublish")
    @Operation(summary = "撤销发布竞赛")
    public R<Void> cancelPublish(Long examId){
        return BaseController.toR(examService.cancelPublish(examId));
    }
}
